if exists(select name from sysobjects where name = 'sp_YouTubeGetAllByTrangThai2')
	drop proc sp_YouTubeGetAllByTrangThai2
go
/*-- =============================================
	Created by: HP
	Created on: 2014-04-22 (dd/mm/yyyy)
	Description: 
	--

	File:$sql-scripts/Proc.sp_YouTubeGetAllByTrangThai.sql
*/-- =============================================

CREATE PROCEDURE sp_YouTubeGetAllByTrangThai2
    @PageIndex INT = 1,
	@PageSize INT = 10,
	@RecordCount INT=0 OUTPUT,
	@TrangThai tinyint
AS
BEGIN
	select ROW_NUMBER() over(
		order by Youtubeid
	) as RowNumber ,
		a.[YouTubeId],
		a.[Name],
		a.[Images],
		a.[Icon],
		a.[Link],
		a.[ThuTu],
		a.[TrangThai],
		a.[NgayTao]
    into #Results
	FROM
        YouTube a WHERE TrangThai=@TrangThai
    set @RecordCount=(select COUNT(YouTubeId) from #Results)
	select * from #Results  WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
	drop table #Results
END
GO
